/*
 *   Copyright (C) 2010  Jens Kieselbach
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */

package de.kieselbach.swing

import javax.swing.*

import java.awt.Color
import java.awt.Component
import java.awt.Graphics

class SplitButtonIcon implements Icon {

    Icon original
    SplitButtonArrowIcon arrow
    Color lineColor1
    Color lineColor2
    boolean paintRollover
    int gap

    public SplitButtonIcon(Icon orig, boolean pr, int arrowsize, int gapsize) {

        original = orig
        paintRollover = pr
        arrow = new SplitButtonArrowIcon(arrowsize)

        gap = gapsize

        lineColor1 = UIUtilities.lineBorderColor
        lineColor2 = lineColor1.brighter()
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {

        int height = getIconHeight()
        original.paintIcon(c, g, x, y + ((height - original.getIconHeight()) / 2) as int)

        arrow.color = paintRollover ? Color.lightGray : Color.black
        arrow.paintIcon(c, g, x + gap + original.getIconWidth(), y + ((height - arrow.getIconHeight()) / 2) as int)
    }

    public int getIconWidth() {

        return original.getIconWidth() + gap + arrow.getIconWidth()
    }

    public int getIconHeight() {

        return Math.max(original.getIconHeight(), arrow.getIconHeight())
    }
}

